0.9 Study the following method:
public void mystery (int n)
{
System.out.print ("For n = " + n);
while (n > 1)
if (n % 2 == 0)
n = n / 2;
else
n = 3 * n + 1;
System.out.println (", the loop terminated.");
} // method mystery
Trace the execution of this method when n = 7. In the same class as the method mystery, develop a main method and a run method to show that the while statement in the method mystery successfully terminates for any positive integer n less than 100. Cultural note: It can be shown that this method terminates for all int values greater than 0, but it is an open question whether the method terminates for all integer values greater than 0.
 
 
View Solution
 
 
 
<< Back